const express = require('express')
const { Comment } = require('../models/comment')

const router = express.Router()

router.post('/add', express.json(), async (req, res) => {
  const comment = await Comment.create(req.body)
  res.send({ code: 0, msg: 'ok', data: comment })
})

router.get('/list', async (req, res) => {
  const comments = await Comment.findAll()
  const comment = comments[0]

  const user = await comment.getUser()
  const article = await comment.getArticle()

  const theUserAllComments = await user.getComments({ where: { content: '呵呵哒222' } })

  res.send({ code: 0, msg: 'ok', data: { comments, user, article, theUserAllComments } })
})

module.exports = {
  router
}